		var addDayArray=[];
          var editIndex = undefined;
          $('#tt').edatagrid({
           	url:"/reserveAddConfig/list?mark="+$('#mark').val(),
            onClickRow: function(index){
            	 if($('#mark').val()==''){return};
                 if(index!=editIndex){
                     editIndex = index;
                  }
             },
             onLoadSuccess:function(data){
             	$(this).datagrid('enableDnd');
             	addDayArray=[];

             	if(data.rows.length==0){
             		if($('#mark').val()==''){
             			 $('#tt').datagrid({
 	                        url:'',
 	                        data:''
             			 }); 
             		}else{
                   	 var data1 = [
                	              {"addDay": "2",'addRate':''},
                	              {"addDay": "3",'addRate':''},
                	              {"addDay": "4",'addRate':''},
                	              {"addDay": "5",'addRate':''},
                	          ];
             			$('#tt').datagrid({
 	                        url:'',
 	                        data:data1
             			 }); 
             			
             		}
            	}else{
                  	$.each(data.rows,function(index,mod){
                		addDayArray.push(mod.addDay)
                	})
            	}
             },
             onBeforeSave:function(index){
            	 var addDayVal=$("td[field='addDay'] input").val();
            	 var addRateVal=$("td[field='addRate'] input").val();
            	 if(addDayVal==''){
            		 return false; 
            	 }
            	 if(addRateVal==''){
            		 
            		 return false; 
            	 }
             }
          });
         //查询
         function doSearch(){
          	$('#tt').edatagrid({
          		url:"/reserveAddConfig/list?mark="+$('#mark').val()});
         }
         //添加
         function addRow(){
         	var markId=$('#mark').val();
         	if(markId==''){return}
         	var file='/resources/js/easyui/datagrid-dnd.js';
         	$('#tt').edatagrid('appendRow', {
         		mark:markId,    
                addDay:''
            });
            $('#tt').datagrid('enableDnd');
         }

          //保存
		function saveRow(){
		    var markId=$('#mark').val();
         	if(markId==''){return}
            var newRow=[];
            var arrayLen=0;
            $('#tt').edatagrid('saveRow')
            var initRow=$("#tt").datagrid('getRows');
 		  	$.each(initRow,function(index,mod){
		  		if(mod.addRate===''||mod.addDay==''||mod.addRate==0){
			  		
		  		}else{
		  			var	array={};
			  		array={addRate:mod.addRate,addDay:mod.addDay,mark:markId};
			  		newRow.push(array);
			  		arrayLen=newRow.length;
		  		}
		  		
		  	})
		  
		  	$.ajax({
		  		url:'/reserveAddConfig/save',
		  		type:'post',
		  		dataType:"json",
		  		data:JSON.stringify(newRow),
		  		contentType:'application/json',
		  		success:function(){
		  			jQuery.messager.alert('提示:','成功保存'+arrayLen+'条数据!'); 
		  			doSearch();
		  		}
		  	})
            
        }
        //删除
        function remove(){
            if (editIndex == undefined){return}
            var row = $('#tt').datagrid('getSelected');
            var array={addRate:row.addRate,addDay:row.addDay,mark:row.mark,id:row.id}
        	$.ajax({
		  		url:'/reserveAddConfig/delete',
		  		type:'post',
		  		dataType:"json",
		  		data:JSON.stringify(array),
		  		contentType:'application/json',
		  		success:function(){
		  			jQuery.messager.alert('提示:','删除成功!'); 
		  			editIndex = undefined;
		  			doSearch();
		  		}
		  	})
          
        }
        //输入框限制为数字
		$(document).on("keyup afterpaste","td[field='addDay'] input",function(){
			this.value=this.value.replace(/\D/g,'');
		})
		//占比输入框限制，最大为100且只最多能有两位小数点 
		$(document).on("keyup afterpaste","td[field='addRate'] input",function(e){
				 this.value = this.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符   
				 this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的   
				 this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
				 this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数   
				 if(this.value.indexOf(".")< 0 && this.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
					 this.value= parseFloat(this.value);  
				 }  
				 if(this.value>100){
					 this.value = 100;
				 }
		})
		
		$(document).on('blur', '.datagrid-view td[field=addDay] input', function(){
			var inputVal=this.value;
			$.each(addDayArray,function(index,mod){
				if(mod==inputVal){
					inputVal='';
					jQuery.messager.alert('提示:','留存天数不能重复!');	
				}
			})
			$(this).val(inputVal);
		});
  
	  
		